<template>
	<div class="home">11</div>
</template>

<script>
import loadJsPdf from '@/utils/jspdf'
const pageLoadStatus = {
	// 等待下下载
	WAIT: 0,
	// 已经下载
	LOADED: 1
}
export default {
	name: 'Home',
	mounted() {
		this.init()
	},
	methods: {
		async init() {
			await loadJsPdf()
			// const vm = this
			const url = 'https://clearlywind.com/pdf/JavaScript设计模式与开发实践.pdf'
			const loadingTask = window.pdfjsLib.getDocument(url)
			// let startPage = 1
			loadingTask.promise.then(pdfDoc => {
				console.log(pdfDoc)
				// pdfDoc.numPages 是总页数
				for (let i = 0; i < pdfDoc.numPages; i += 1) {
					// const pageIndex = startPage + i
					// const page = pages[pageIndex - 1]
					// if (page.loadStatus !== pageLoadStatus.LOADED) {
					// 	pdfDoc.getPage(i + 1).then(pdfPage => {
					// 		page.pdfPage = pdfPage
					// 		page.loadStatus = pageLoadStatus.LOADED
					// 		console.log(pages)
					// 		// 通知可以进行渲染了
					// 		// startRenderPages()
					// 	})
					// }
				}
			})
		},
		initPages(totalPage) {
			const pages = []

			for (let i = 0; i < totalPage; i += 1) {
				pages.push({
					pageNo: i + 1,
					loadStatus: pageLoadStatus.WAIT,
					pdfPage: null,
					dom: null
				})
			}
		},
		async fetchPdfFragment(pageIndex) {
			return {
				// 分片的开始页码
				startPage: pageIndex,
				// 分片结束页码
				endPage: pageIndex - 1 + 5,
				// pdf 总页数
				totalPage: 0,
				url: 'https://clearlywind.com/pdf/JavaScript设计模式与开发实践.pdf'
			}
		}
	}
}
</script>
